package com.example.casper.Experiment2024.Database;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import android.content.Context;

@Database(entities = {PunchRecord.class}, version = 1,exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
    private static AppDatabase INSTANCE;

    public abstract PunchRecordDao punchRecordDao();

    public static AppDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            AppDatabase.class, "punch_database")
                    .allowMainThreadQueries() // 允许在主线程中执行查询（不推荐，实际使用中应使用异步任务）
                    .build();
        }
        return INSTANCE;
    }
}